package demo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import demo.interceptor.DemoInterceptor;

@Path("/hello")
public class HelloController extends Controller {
    public void index() {
          renderText("Hello JFinal World.");
    }

    // 通过getPara获取get请求参数
    public void test() {
        String userName = getPara("userName");
        renderText("参数:" + userName);
    }

    // 通过参数注入获取参数
    public void  test2(String userName, String passWord) {

        renderText("参数:" + userName + passWord);
    }

    // 获取json数据
    public void test3() {
        String json = getRawData();
        JSONObject jsonObject = JSON.parseObject(json);
        renderText("json数据为：" +jsonObject.getString("userName"));
    }

    // 方法拦截器
    //@Before(DemoInterceptor.class)
    @Clear
    public void interceptorTest() {
        renderText("interceptorTest");
    }
}
